# t1 = [1, 2, 3, 4]
# t2 = t1[:]
# t1[-1] = 5
# print(t2)

d1 = [
    {
        'name': 'x',
        'age': 1,
    },
    {
        'name': 'xxx',
        'age': 3,
    },
    {
        'name': 'xx',
        'age': 2,
    }
]
d1.sort(key=lambda x: x.get('age'), reverse=True)
# print(d1)

# class Student:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age

from dataclasses import dataclass
from enum import Enum


class SexEnum(Enum):
    OTHER = 0
    MAIL = 1
    FEMAIL = 2


@dataclass
class Student:
    name: str
    age: int


# 服务器配置不一样,


def wrapper(*args, **kwargs):
    def inner(func):
        # 修改前
        res = func(*args, **kwargs)
        # 修改后
        return res
    return inner


class ChangeEnum(Enum):
    ADD = 'add'
    UPDATE = 'update'
    DEL = 'del'


def diff(json1, json2):
    res = []
    j1_keys = set(json1.keys())
    j2_keys = set(json2.keys())
    common_keys = j1_keys & j2_keys
    del_keys = j1_keys - j2_keys
    add_keys = j2_keys - j1_keys

    update_keys = []
    for k in common_keys:
        j1_v = json1[k]
        j2_v = json2[k]
        if j1_v != j2_v:
            update_key = {
                'k': k,
                'origin': j1_v,
                'after': j2_v,
                'op': ChangeEnum.UPDATE.value
            }
            res.append(update_key)
    for k in del_keys:
        v = json1[k]
        del_key = {
            'k': k,
            'origin': v,
            'after': None,
            'op': ChangeEnum.DEL.value
        }
        res.append(del_key)
    for k in add_keys:
        v = json2[k]
        add_key = {
            'k': k,
            'origin': None,
            'after': v,
            'op': ChangeEnum.ADD.value
        }
        res.append(add_key)
    return res


j1 = {'a': 1, 'b': 2, 'cpu': {'throttle': 70, 'level': 1}}
j2 = {'a': 2, 'c': 2, 'cpu': {'throttle': 80, 'level': 2}}
res = diff(j1, j2)
print(res)
